/// <license>
/// Copyright (c) 2002-2008, DotNetNuke Corporation
/// All rights reserved
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
/// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
/// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
/// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
/// of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
/// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
/// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
/// DEALINGS IN THE SOFTWARE.
/// </license>

#region Using Statements

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;

using DotNetNuke.Common.Utilities;

using DotNetNuke.ModuleToolkit.Modules.Data;

#endregion

namespace DotNetNuke.ModuleToolkit.Modules.Extensions
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// Business Layer class for Extensions
    /// </summary>
    /// <history>
    ///     [cnurse]  10/11/2007  Created
    /// </history>
    /// -----------------------------------------------------------------------------
    public static class ExtensionController
    {

        #region Public Static Methods

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Adds a Extension to the DataStore
        /// </summary>
        /// <param name="section">The Extension to persist</param>
        /// <returns>An integer that represents the Id of the new Extension</returns>
        /// <history>
        /// 	[cnurse]	10/12/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static int AddExtension(ExtensionInfo Extension)
        {
            return DataService.CreateExtension(Extension.PackageId, Extension.DesktopModuleId, Extension.Name, Extension.IExtensionClass);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Deletes a Extension from the DataStore
        /// </summary>
        /// <param name="section">The Extension to delete</param>
        /// <history>
        /// 	[cnurse]	10/13/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void DeleteExtension(ExtensionInfo Extension)
        {
            DataService.DeleteExtension(Extension.ExtensionId);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets Extension from the Data Store
        /// </summary>
        /// <param name="ExtensionId">The id of the Extension</param>
        /// <returns>A ExtensionInfo object</returns>
        /// <history>
        ///     [cnurse]  10/13/2007  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static ExtensionInfo GetExtension(int ExtensionId)
        {
            return CBO.FillObject<ExtensionInfo>(DataService.GetExtension(ExtensionId));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets Extension from the Data Store
        /// </summary>
        /// <param name="desktopModuleId">The id of the module</param>
        /// <param name="ExtensionName">The name of the Extension</param>
        /// <returns>A ExtensionInfo object</returns>
        /// <history>
        ///     [cnurse]  10/11/2007  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static ExtensionInfo GetExtensionByName(int desktopModuleId, string ExtensionName)
        {
            return CBO.FillObject<ExtensionInfo>(DataService.GetExtensionByName(desktopModuleId, ExtensionName));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets a Extension from the Data Store by its Package Id
        /// </summary>
        /// <param name="packageId">The id of the package</param>
        /// <returns>A ExtensionInfo object</returns>
        /// <history>
        ///     [cnurse]  10/13/2007  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static ExtensionInfo GetExtensionByPackageID(int packageId)
        {
            return CBO.FillObject<ExtensionInfo>(DataService.GetExtensionByPackageID(packageId));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets the Extensions for a module from the Data Store
        /// </summary>
        /// <param name="desktopModuleId">The id of the module</param>
        /// <returns>A List of ExtensionInfo objects</returns>
        /// <history>
        ///     [cnurse]  10/11/2007  Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static List<ExtensionInfo> GetExtensions(int desktopModuleId)
        {
            return CBO.FillCollection<ExtensionInfo>(DataService.GetExtensions(desktopModuleId));
        }

        #endregion

    }
}
